<?php
// 应用公共文件

//生成随机字符串
function creatToken($length=10)
{
	$characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
	$randomString = '';
	for ($i = 0; $i < $length; $i++) {
	    $randomString .= $characters[rand(0, strlen($characters) - 1)];
	}
	
	return $randomString;
}


// 返回状态字符串
function callStatusStr($goods_name,$status)
{
	if($status==0){
		$str = '退货状态商品'.$goods_name.'不能操作';
	}
	if($status==1){
		$str = '采购状态商品'.$goods_name.'不能操作';
	}
	if($status==2){
		$str = '批发状态商品'.$goods_name.'不能操作';
	}
	if($status==3){
		$str = '批发退货状态商品'.$goods_name.'不能操作';
	}
}

//二维数组降维 转逗号分隔
function togglecomma($arr,$key)
{
	$array = [];
	foreach($arr as $val){
		array_push($array,$val[$key]);
	}
	return implode(',',$array);
}

//post请求
function post_https_request($url,$post_data)
{
	$ch = curl_init();
	curl_setopt($ch , CURLOPT_URL , $url);
	curl_setopt($ch, CURLOPT_POST, 1);
	curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
	curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); 
	curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 5);
	curl_setopt($ch, CURLOPT_HEADER, false);
	$res = curl_exec($ch);
	curl_close($ch);
	return $res;
}


